﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'auction';
domain = 'http://img1.chinalaohu.com';
</cfscript>
<cfparam name="platform" default="0" >

<cffunction name="list" access="remote" returntype="any" returnFormat="json">
<!---<cftry>--->
<cfparam name="lastleixin" default="" type="string">

	<cfscript>
	if (isdefined('groupFilter') and isdefined('childFilter')){
		if (listlen(groupFilter) neq listlen(childFilter)){
			return {"success":"0"};
		}
		else{
			gf = listtoarray(GROUPFILTER);
			cf = listtoarray(CHILDFILTER);
		}
	}
	</cfscript>



  <cfparam name="page" default="0">
  <!---DEBUG--->
  <!---<cfquery datasource="#DB#">
  insert into tmp(post,act,dt)
  value('#serializeJSON(form)#','LIST',#now()#)
  </cfquery>--->
  
  <cfscript>
	if (not isdefined('pagesize')){
		pagesize = 15;
	}
	//startrow = ;
	if (isdefined('preview') and preview eq 1){
		p = 1;
	}
	else {	
		p = 0;
	}
	if (isdefined('auction') and auction eq 1){
		a = 1;
	}
	else {
		a = 0;
	}
	if (isdefined('deal') and deal eq 1){
		d = 1;
	}
	else {
		d = 0;
	}
	pad = p & a & d;
	
	if (isdefined('order')){
		if (not isnumeric(order)){
			order = 0;
		}
		
		switch(order){
			case 1:
				orderby = 'auction.prevtime desc,endtime ASC';
			  break;
			case 2:
				orderby = 'auction.prevtime desc,if(lastprice = 0,startprice,lastprice) DESC';
			  break;
			case 3:
				orderby = 'auction.prevtime desc,if(lastprice = 0,startprice,lastprice) ASC';
			  break;
			case 4:
				orderby = 'auction.prevtime desc,bids DESC';
			  break;
			case 5:
				orderby = 'auction.prevtime desc,endtime DESC';
			  break;
			//默认排序加图片
			case 0:
				if (isdefined('brandid') and (brandid eq 3 or brandid eq 4) and pad eq '000'){
					orderby = 'auction.prevtime desc, acode asc';
					//以类型为基础显示图片
					lxpic = '';	
				}
				break;
			default:
				orderby = 'auction.prevtime desc, acode asc';
			  break;
		}
		
	}
	else if (not isdefined('title') or (isdefined('title') and len(title) eq 0)){
		//瓷器
		if (isdefined('brandid') and (brandid eq 3 or brandid eq 4) and pad eq '000'){
			orderby = 'auction.prevtime desc,acode asc';
			//以类型为基础显示图片
			lxpic = '';	
		}
	}
	</cfscript>
  
  <cfquery datasource="#DB#" name="auctionrc">
  SELECT
  aid
  FROM
  auction
  WHERE 
	is_delete = 0 and atag > 0 AND prevtime <= #now()#
  <cfif (isdefined('cateID') and (len(cateID) gt 0 AND cateID gt 0)) or (isdefined('brandid') and (len(brandid) gt 0 AND brandid gt 0))> and endtime >= #now()# </cfif>
  <cfif isdefined('cateID') and (len(cateID) gt 0 AND cateID gt 0)>AND (pcid=#cateID# or (pcid2=#cateID# and pcid2 > 0))</cfif>
  <cfif isdefined('brandid') and (len(brandid) gt 0 AND brandid gt 0)>AND pbid=#brandid#</cfif>
  <cfif isdefined('title') and len(title) gt 0>
  AND auction.auction like '%#title#%'
  </cfif>
<!---  <cfif isdefined('sprice') and isnumeric(sprice)>
  AND if(lastprice = 0,startprice,lastprice) >= #sprice#
  </cfif>
  <cfif isdefined('eprice') and isnumeric(eprice)>
  AND if(lastprice = 0,startprice,lastprice) <= #eprice#
  </cfif>--->
  <cfif isdefined('gf') and arraylen(gf) gt 0>
    <cfloop from="1" to="#arraylen(gf)#" index="f">
    	<cfswitch expression="#gf[f]#">
      	<cfcase value="sprice">
         AND if(lastprice = 0,startprice,lastprice) >= #listfirst(cf[f],'|')# AND if(lastprice = 0,startprice,lastprice) < #listlast(cf[f],'|')# 
        </cfcase>
      	<cfdefaultcase>
          AND #gf[f]# = '#cf[f]#'
        </cfdefaultcase>
      
      </cfswitch>
    </cfloop> 
  </cfif>
  <cfswitch expression="#pad#">
  <cfcase value="100">
  AND starttime > #now()#<!---预展--->
  </cfcase>
  <cfcase value="010">
  AND starttime <= #now()# and endtime >= #now()#<!---竞拍--->
  </cfcase>
  <cfcase value="001">
  AND endtime <= #now()#<!---结标--->
  </cfcase>
  <cfcase value="110">
  AND endtime > #now()#<!---预展~结标--->
  </cfcase>
  <cfcase value="101">
  AND (starttime > #now()# OR endtime <= #now()#)<!---预展~结标--->
  </cfcase>
  <cfcase value="111">
  </cfcase>
  <cfcase value="000">
  </cfcase>
  </cfswitch>
  </cfquery>

  <cfscript>
	aidlist = valuelist(auctionrc.aid);
	if (aidlist eq '') aidlist = 0;
	</cfscript>
    <cfquery datasource="#DB#" name="auctionlist"> 
    SELECT
    auction.aid,
    auction.atype,
    auction.atag,
    acode,
    auction.auction AS aname,
    auction.startprice,
    auction.oneprice,
    auction.lastprice,
    if(lastprice = 0,startprice,lastprice) as showprice,
    prevtime,
    starttime,
    endtime,
    auction_gallery.img_waterfall,leixin
    FROM
    auction
    INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
    WHERE 
    auction.aid in (#aidlist#)
    <cfif isdefined('orderby')>
    ORDER BY #orderby#,aid DESC
    </cfif>
    <cfif isdefined('page') and isnumeric(page)>limit #page * pagesize#,#pagesize#</cfif>
    </cfquery>
<!---会员相关--->  
<cfif isdefined('uuid') and len(uuid) gte 32>
<!---关注--->
<cfquery datasource="#DB#" name="usergzlist">
select aid
from user_concern
INNER JOIN user_base ON user_base.uid = user_concern.uid
where user_base.muuid = '#uuid#'
</cfquery>
<cfscript>
if (usergzlist.recordcount gt 0){
	usergz = valuelist(usergzlist.aid);
}
else {
	usergz = '';
}
</cfscript>
</cfif>
<cfscript>
rs = StructNew();
StructAppend(rs,{"success":"1"});
//是否过滤
/*1、竞价预展成交为全部时:000或111
2、没提交价格或是价格为空
3、父子过滤字段不存在或为空
4、没title或title长度为0*/
if (pad neq '000' and pad neq '111'){
	is_filter = 1;	
}
else if (isdefined('title') and len(title) gt 0){
	is_filter = 1;	
}
else if (isdefined('sprice') and len(sprice) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('eprice') and len(eprice) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('groupFilter') and len(groupFilter) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('childFilter') and len(childFilter) gt 0 ){
	is_filter = 1;	
}
else if (isdefined('order') and order neq 0){
	is_filter = 1;
}

</cfscript>
<!---要求返回--->
<cfif isdefined('showSF') and showSF eq 1>
<cfscript>
filter = arraynew(1);
classchild = arraynew(1);
brandchild = arraynew(1);
</cfscript>

<!---分类--->
<cfif isdefined('title') and len(title) gt 0>
<cfquery datasource="#DB#" name="classlist">
select pcid,pclass
from pin_class
where fpcid = 0
order by pcorder asc
</cfquery>
<cfoutput query="classlist">
<cfscript>
classjson = {
	"name":pclass,
  "value":pcid
};
arrayappend(classchild,classjson);
</cfscript>
</cfoutput>
<cfscript>
classselect = {"name":"分类","value":"cateId","child":classchild};
arrayappend(filter,classselect);
</cfscript>
</cfif>



<!---品牌--->
<cfif not isdefined('brandid')>
<cfquery datasource="#DB#" name="bandlist">
select pbid AS brandid,pbrands,platin,pcid
from pin_brands
<cfif isdefined('cateID') and (len(cateID) gt 0 AND cateID gt 0)>where pcid = #cateid#</cfif>
order by pborder asc
</cfquery>
<cfoutput query="bandlist">
<cfscript>
brandjson = {
	"name":pbrands,
  "value":brandid
};

arrayappend(brandchild,brandjson);

</cfscript>
</cfoutput>
<cfscript>
brandselect = {"name":"品牌","value":"brandId","child":brandchild};
//writedump(brand);
arrayappend(filter,brandselect);
</cfscript>
</cfif>

<!---材质--->
<cfquery datasource="#DB#" name="chizhilist">
SELECT DISTINCT
auction.chizhi
FROM auction
WHERE
chizhi <> '' AND
aid IN (#aidlist#)
</cfquery>

<cfif chizhilist.recordcount gt 0>
	<cfset brandchild = arraynew(1)>
  <cfoutput query="chizhilist">
		<cfset arrayappend(brandchild,{"name":#chizhi#,"value":#chizhi#})>
  </cfoutput>
  <cfscript>
	chizhiselect = {"name":"材质","value":"chizhi","child":brandchild};
	arrayappend(filter,chizhiselect);
	</cfscript>  
</cfif>

<!---类型--->
<cfquery datasource="#DB#" name="leixinlist">
SELECT DISTINCT
auction.leixin
FROM auction
WHERE
leixin <> '' AND
aid IN (#aidlist#)
</cfquery>

<cfif leixinlist.recordcount gt 0>
	<cfset leixinchild = arraynew(1)>
  <cfoutput query="leixinlist">
		<cfset arrayappend(leixinchild,{"name":#leixin#,"value":#leixin#})>
  </cfoutput>
  <cfscript>
	leixinselect = {"name":"类型","value":"leixin","child":leixinchild};
	arrayappend(filter,leixinselect);
	</cfscript>  
</cfif>



<cfscript>
//价格
priceselect = {"name":"价格区间",
"value":"sprice",
"child":[
{"name":"0-50元","value":"0|50"},
{"name":"50-100元","value":"50|100"},
{"name":"100-500元","value":"100|500"},
{"name":"500-1000元","value":"500|1000"},
{"name":"1000-2000元","value":"1000|2000"},
{"name":"2000-5000元","value":"2000|5000"},
{"name":"5000元以上","value":"5000|999999999"}
]
};
arrayappend(filter,priceselect);
</cfscript>

<!---分类--->
<cfscript>
StructAppend(rs,{"filter":filter});

sort = [
{"name":"默认","value":"0"},
{"name":"价格从低到高","value":"3"},
{"name":"价格从高到低","value":"2"},
{"name":"结标时间从近到远","value":"1"},
{"name":"结标时间从远到近","value":"5"},
{"name":"人气排序","value":"4"}
];
StructAppend(rs,{"sort":sort});

</cfscript>
</cfif>
<cfscript>
StructAppend(rs,{"count":auctionrc.recordcount});
StructAppend(rs,{"serverTime":datetimeformat(now(),'yyyy-mm-dd HH:nn:ss')});


//输出提交参数
/*
postParas = {
	"lastleixin":lastleixin
};

StructAppend(rs,{"postParas":postParas});
*/

list = arraynew(1);
/*if (auctionrc.rc gt 0){
	//品牌才有图片
	if (not isdefined('is_filter')){
		arrayappend(list,{"imgUrl":"http://adio.chnalaohu.com/app/pic/home_darktea.jpg"});
	}
}*/
</cfscript>
<!---顶部图片

<cfif page eq 0 AND auctionrc.recordcount gt 0 and not isdefined('is_filter')>
	<cfif isdefined('cateId') and cateId gt 0>
  	<!---分类图片显示--->
  	<cfquery datasource="#DB#" name="classimg">
    select pcimgurl
    from pin_class
    where pcid = #cateId#
    </cfquery>
    <cfscript>
		if (classimg.recordcount gt 0 and len(classimg.pcimgurl) gt 7){
			arrayappend(list,{"imgUrl":classimg.pcimgurl});
		}
		</cfscript>
  <cfelseif isdefined('brandId') and brandId gt 0>  
  	<!---分品牌图片显示--->
  	<cfquery datasource="#DB#" name="brandimg">
    select pbimgurl
    from pin_brands
    where pbid = #brandId#
    </cfquery>
    <cfscript>
		if (brandimg.recordcount gt 0 and len(brandimg.pbimgurl) gt 7){
			arrayappend(list,{"imgUrl":brandimg.pbimgurl});
		}
		</cfscript>
  </cfif>
</cfif>--->
<cfif isdefined('url.dump')>
<cfdump var="#pad#">
<cfdump var="#list#">
</cfif>
<cfoutput query="auctionlist">
<cfscript>
attention = 0;
if (isdefined('usergz') and usergz neq ''){
	if (listfind(usergz,aid) gt 0){
		attention = 1;
	}
}



//需要加图片
if (isdefined('lxpic')){
	if ((isdefined('gf') and arraylen(gf) gt 0) or (isdefined('cf') and arraylen(cf) gt 0)){
		
	}
	else {
		if (lxpic neq leixin){
			lxpic = leixin;
			
			
			leixinlistCFC=CreateObject("component","app.cfc.lists").leixinlist(specval=leixin);
			//arrayappend(list,{"imgUrl":"http://www.zenlifestore.com/Public/Uploads/Onlineshop/Advert/51d3b35be217a.jpg"});
			////征艺廊不显示图片
			if (not isdefined('brandid') or brandid neq 3) {
				if (len(leixinlistCFC.specpic) gt 5){
					if (page eq 0 or lastleixin neq leixin){
						//arrayappend(list,{"imgUrl":leixinlistCFC.specpic});
					}
				}
			}
		}
	}
}

switch(platform){
	case 0:
		iconUrl = domain & img_waterfall;
		if (left(img_waterfall,8) eq '/upload/' and left(img_waterfall,13) neq '/upload/adio/'){
			iconUrl = domain & replacenocase(img_waterfall,'/upload/','/upload/adio/');
		}
		break;
	case 1:
		iconUrl = domain & img_waterfall;
		if (left(img_waterfall,8) eq '/upload/' and left(img_waterfall,12) neq '/upload/ios/'){
			iconUrl = domain & replacenocase(img_waterfall,'/upload/','/upload/ios/');
		}
		break;
}


listjson = {
"aID":aid,
"auctionCode": acode,
"iconUrl":iconUrl,
"name":aname,
"price":showprice, 
"attention":attention,
"leixin":leixin
};
if (DateCompare(now(), endtime) gte 0){
	auctionType = 2;//成交
	structappend(listjson,{"dealTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), starttime) gte 0){
	auctionType = 1;//拍卖
	structappend(listjson,{"lastTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), prevtime) gte 0){
	auctionType = 0;//预展
	structappend(listjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
	structappend(listjson,{"preETime":datetimeformat(starttime,'yyyy-mm-dd HH:nn')});
}
else {
	auctionType = -1;//待展
	structappend(listjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
}

structappend(listjson,{"auctionType":auctionType});
/*showprice = lastprice;
if (showprice eq 0){
	showprice = startprice;
}
"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn'),
"preETme":datetimeformat(starttime,'yyyy-mm-dd HH:nn'),
"lastTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn'),

*/



arrayappend(list,listjson);
</cfscript>
</cfoutput>
<cfscript>
StructAppend(rs,{"list":list});
if (isdefined('dump')){
	writedump(rs);
}

rs = createObject("component",'cfjson').encode(rs);
return rs;

</cfscript>

<!---<cfcatch type="any">
<cfscript>
rs = {"success":"0"};
rs = createObject("component",'cfjson').encode(rs);
return rs;
</cfscript>
</cfcatch>



</cftry>--->
	</cffunction>
  
  
  <!---规格：磁器类型--->
  <cffunction name="leixinlist" access="remote" returntype="query">
  	<cfquery datasource="#DB#" name="leixinlist">
    select specval,specpic
    from pin_spec
    where pcid = 1
    <cfif isdefined('specval')>AND specval='#specval#'</cfif>
    </cfquery>
    <cfreturn leixinlist>
  </cffunction>
  
  
</cfcomponent>